package com.example.service;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.example.entity.Member;

import com.example.mapper.MemberMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Transactional
@Service
public class MemberService   {
    @Resource
    private MemberMapper memberMapper;

    /**
     * 新增
     */
    public void add(Member member) {
        member.setTime(DateUtil.today());

        memberMapper.insert(member);
    }

    /**
     * 删除
     */
    public void deleteById(Integer id) {
        memberMapper.deleteById(id);
    }

    /**
     * 批量删除
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            memberMapper.deleteById(id);
        }
    }

    /**
     * 修改
     */
    public void updateById(Member member) {
        member.setTime(DateUtil.today());
        memberMapper.updateById(member);
    }

    /**
     * 根据ID查询
     */
    public Member selectById(Integer id) {

        return memberMapper.selectById(id);
    }

    /**
     * 查询所有
     */
    public List<Member> selectAll(Member member) {
        return memberMapper.selectAll(member);
    }

    /**
     * 分页查询
     */
    public PageInfo<Member> selectPage(Member member, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Member> list = memberMapper.selectAll(member);
        return PageInfo.of(list);
    }



    public List<Member> list(Wrapper<Member> queryWrapper) {
        return memberMapper.selectList(queryWrapper);
    }
}
